import java.util.concurrent.CompletableFuture;

/**
 * 每一行代码，都是改变世界的力量
 *
 * @author 郭帅
 * @date 2022/11/11 16:14
 */
public class CompletableRelationTest {

    public static void main(String[] args) {
        // 组合两个任务
        CompletableFuture<String> first = CompletableFuture.supplyAsync(() -> {
            System.out.println(1 / 0);
            return "name: ";
        });

        CompletableFuture<String> second = CompletableFuture.supplyAsync(() -> {
            System.out.println("second");
            return "mojiruo ";
        }).thenCombine(CompletableFuture.supplyAsync(() -> {
            System.out.println(1 / 0);
            return "name: ";
        }).exceptionally(throwable -> "name2: "), (s, w) -> {
            System.out.println(s);
            System.out.println(w);
            return s + w;
        });
        System.out.println(second.join());
    }


}
